package il.ac.bgu.cs.heuristics.utils;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import junit.framework.Assert;
import junit.framework.TestCase;

import org.junit.Test;

/**
 * 
 * @author Ronen Pinko
 * 
 */
public class PermutationTests extends TestCase{

	private static final String BANANAS = "bananas";
	private static final String ROOM2 = "room2";
	private static final String ROOM1 = "room1";
	private static final String CHAIR = "chair";
	private static final String MONKEY = "monkey";

	@Test
	public void testPermutations01() {
		final Set<String> constants = CollectionUtils.newLinkedHashSet();
		constants.add(MONKEY);
		constants.add(CHAIR);
		constants.add(ROOM1);
		constants.add(ROOM2);
		constants.add(BANANAS);
		final Set<List<String>> permutations = MathUtils.createKPermutations(
		        constants, 3);
		final Set<List<String>> expected = CollectionUtils.newLinkedHashSet();

		expected.add(Arrays.asList(MONKEY, CHAIR, ROOM1));
		expected.add(Arrays.asList(MONKEY, ROOM1, CHAIR));
		expected.add(Arrays.asList(CHAIR, MONKEY, ROOM1));
		expected.add(Arrays.asList(ROOM1, MONKEY, CHAIR));
		expected.add(Arrays.asList(CHAIR, ROOM1, MONKEY));
		expected.add(Arrays.asList(ROOM1, CHAIR, MONKEY));
		expected.add(Arrays.asList(MONKEY, CHAIR, ROOM2));
		expected.add(Arrays.asList(MONKEY, ROOM2, CHAIR));
		expected.add(Arrays.asList(CHAIR, MONKEY, ROOM2));
		expected.add(Arrays.asList(ROOM2, MONKEY, CHAIR));
		expected.add(Arrays.asList(CHAIR, ROOM2, MONKEY));
		expected.add(Arrays.asList(ROOM2, CHAIR, MONKEY));
		expected.add(Arrays.asList(MONKEY, CHAIR, BANANAS));
		expected.add(Arrays.asList(MONKEY, BANANAS, CHAIR));
		expected.add(Arrays.asList(CHAIR, MONKEY, BANANAS));
		expected.add(Arrays.asList(BANANAS, MONKEY, CHAIR));
		expected.add(Arrays.asList(CHAIR, BANANAS, MONKEY));
		expected.add(Arrays.asList(BANANAS, CHAIR, MONKEY));
		expected.add(Arrays.asList(MONKEY, ROOM1, ROOM2));
		expected.add(Arrays.asList(MONKEY, ROOM2, ROOM1));
		expected.add(Arrays.asList(ROOM1, MONKEY, ROOM2));
		expected.add(Arrays.asList(ROOM2, MONKEY, ROOM1));
		expected.add(Arrays.asList(ROOM1, ROOM2, MONKEY));
		expected.add(Arrays.asList(ROOM2, ROOM1, MONKEY));
		expected.add(Arrays.asList(MONKEY, ROOM1, BANANAS));
		expected.add(Arrays.asList(MONKEY, BANANAS, ROOM1));
		expected.add(Arrays.asList(ROOM1, MONKEY, BANANAS));
		expected.add(Arrays.asList(BANANAS, MONKEY, ROOM1));
		expected.add(Arrays.asList(ROOM1, BANANAS, MONKEY));
		expected.add(Arrays.asList(BANANAS, ROOM1, MONKEY));
		expected.add(Arrays.asList(MONKEY, ROOM2, BANANAS));
		expected.add(Arrays.asList(MONKEY, BANANAS, ROOM2));
		expected.add(Arrays.asList(ROOM2, MONKEY, BANANAS));
		expected.add(Arrays.asList(BANANAS, MONKEY, ROOM2));
		expected.add(Arrays.asList(ROOM2, BANANAS, MONKEY));
		expected.add(Arrays.asList(BANANAS, ROOM2, MONKEY));
		expected.add(Arrays.asList(CHAIR, ROOM1, ROOM2));
		expected.add(Arrays.asList(CHAIR, ROOM2, ROOM1));
		expected.add(Arrays.asList(ROOM1, CHAIR, ROOM2));
		expected.add(Arrays.asList(ROOM2, CHAIR, ROOM1));
		expected.add(Arrays.asList(ROOM1, ROOM2, CHAIR));
		expected.add(Arrays.asList(ROOM2, ROOM1, CHAIR));
		expected.add(Arrays.asList(CHAIR, ROOM1, BANANAS));
		expected.add(Arrays.asList(CHAIR, BANANAS, ROOM1));
		expected.add(Arrays.asList(ROOM1, CHAIR, BANANAS));
		expected.add(Arrays.asList(BANANAS, CHAIR, ROOM1));
		expected.add(Arrays.asList(ROOM1, BANANAS, CHAIR));
		expected.add(Arrays.asList(BANANAS, ROOM1, CHAIR));
		expected.add(Arrays.asList(CHAIR, ROOM2, BANANAS));
		expected.add(Arrays.asList(CHAIR, BANANAS, ROOM2));
		expected.add(Arrays.asList(ROOM2, CHAIR, BANANAS));
		expected.add(Arrays.asList(BANANAS, CHAIR, ROOM2));
		expected.add(Arrays.asList(ROOM2, BANANAS, CHAIR));
		expected.add(Arrays.asList(BANANAS, ROOM2, CHAIR));
		expected.add(Arrays.asList(ROOM1, ROOM2, BANANAS));
		expected.add(Arrays.asList(ROOM1, BANANAS, ROOM2));
		expected.add(Arrays.asList(ROOM2, ROOM1, BANANAS));
		expected.add(Arrays.asList(BANANAS, ROOM1, ROOM2));
		expected.add(Arrays.asList(ROOM2, BANANAS, ROOM1));
		expected.add(Arrays.asList(BANANAS, ROOM2, ROOM1));

		Assert.assertEquals(expected, permutations);

	}

}
